<template>
  <div>
    <el-dialog :title="maintitle" :visible.sync="dialogVisible" width="50%">
      <el-form labelWidth="150px">
        <el-form-item label="选择设备" class="is-required" style="width:100%">
          <selecteq :selecteqid.sync="selecteqid"  style="width:100%;margin-right:10px" :isself="true"></selecteq>
          
        </el-form-item>
        <el-form-item label="处理方式" class="is-required" style="width:100%">
          <el-select v-model="newrepairdata.repair_type" placeholder="请选择" style="width:100%">
            <el-option
              v-for="item in repairtypeArr"
              :key="item.value"
              :label="item.hash.code_name"
              :value="item.hash.code_id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="故障现象和维修要求" class="is-required" style="width:100%">
          <el-input
            type="textarea"
            :rows="2"
            v-model="newrepairdata.sq_content"
            placeholder="请输入内容"
          >
          </el-input>
        </el-form-item>
        <el-form-item label="申请时间" class="is-required" style="width:100%">
          <el-date-picker
            type="date"
            style="width:100%"
            v-model="newrepairdata.sqtime"
            placeholder="选择申请时间"
            valueFormat="yyyy-MM-dd"
            clearable
          ></el-date-picker>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="dialogVisible = false">取 消</el-button>
        <el-button size="mini" type="primary" @click="editrepair" v-if="isedit">保 存</el-button>
        <el-button size="mini" type="primary" @click="addrepair" v-else>确 定</el-button>

      </span>
    </el-dialog>
  </div>
</template>

<script>
import selecteq from '~/components/common/selecteq.vue';

export default {

  data() {
    return {
      dialogVisible: true,
      ts: this.newStore(),
      selecteqid: {},
      maintitle: '新增设备维修记录',
      newrepairdata: {
        sqtime: '',
        sq_content: '',
        eid: '',
        repair_type: '',
      },
      repairtypeArr: [],
    };
  },
  props: {
    editdata: Array,
    isedit: Boolean,
  },
  components: {
    selecteq,
  },
  created() {
    this.getcodeData('0404', '04', 'repairtypeArr');
    if (this.isedit) {
      this.maintitle = '编辑维修计记录';
      this.selecteqid = {};
      this.newrepairdata = this.editdata.operation1[0].hash;
      this.selecteqid = this.editdata.operation1[0].hash;
      this.selecteqid.id = this.selecteqid.eid;
    }
  },
  methods: {
    // 公共方法获取代码项
    getcodeData(supid, codetype, arrname) {
      const req = {
        handle: '67A5B6FEF17D97DECF116BDF95B95C0B167942DD3F1604F9',
        supid,
        codetype,
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        this[arrname] = ts.d.data.operation1;
      });
    },
    editrepair() {
      this.$confirm('是否保存设备维修记录?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          const req = this.newrepairdata;
          req.handle = 'DD5D108B99FC12B78456C40D977EBA89DCCC094D1456DACE571521205BF7630EFE55FCA74BA094F5';
          req.eid = this.selecteqid.id;
          req.sqrid = localStorage.getItem('pid');
          this.spost(this.ts, '/mainservlet', req).then((ts) => {
            this.$message({
              type: 'success',
              message: '保存成功!',
            });
            this.dialogVisible = false;
            this.$parent.geteqrepairList();
          });
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消',
          });
        });
    },
    addrepair() {
      this.$confirm('是否添加设备维修记录?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          const req = this.newrepairdata;
          req.handle = 'DD5D108B99FC12B78456C40D977EBA89DCCC094D1456DACE11EFA224B27058AE338C0E01082A5616';
          req.eid = this.selecteqid.id;
          req.sqrid = localStorage.getItem('pid');
          this.spost(this.ts, '/mainservlet', req).then((ts) => {
            this.$message({
              type: 'success',
              message: '添加成功!',
            });
            this.dialogVisible = false;
            this.$parent.geteqrepairList();
          });
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消',
          });
        });
    },
  },
};
</script>


<style scoped>
.el-form-item {
  width: 50%;
  margin-bottom: 22px;
  float: left;
}
</style>
